package com.jianbing.lakk.controller;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jianbing.common.core.domain.model.LoginUser;
import com.jianbing.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.lakk.domain.LakkUserplaytimerecord;
import com.jianbing.lakk.service.ILakkUserplaytimerecordService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * 玩耍记录表Controller
 *
 * @author windbless
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/lakk/UserPlaytimeRecord")
public class LakkUserplaytimerecordController extends BaseController {
    @Autowired
    private ILakkUserplaytimerecordService lakkUserplaytimerecordService;

    /**
     * 查询玩耍记录表列表
     */
//    @PreAuthorize("@ss.hasPermi('lakk:UserPlaytimeRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(LakkUserplaytimerecord lakkUserplaytimerecord) {
         lakkUserplaytimerecord.setUserid(getappid(SecurityUtils.getLoginUser()));
        startPage();
        List<LakkUserplaytimerecord> list = lakkUserplaytimerecordService.selectLakkUserplaytimerecordList(lakkUserplaytimerecord);
        return getDataTable(list);
    }
     @GetMapping("/list1")
    public TableDataInfo list1(LakkUserplaytimerecord lakkUserplaytimerecord) {
        startPage();
        List<LakkUserplaytimerecord> list = lakkUserplaytimerecordService.selectLakkUserplaytimerecordList(lakkUserplaytimerecord);
        return getDataTable(list);
    }

    private Long getappid(LoginUser loginUser) {
        return loginUser.getUserId();
    }

    /**
     * 导出玩耍记录表列表
     */
//    @PreAuthorize("@ss.hasPermi('lakk:UserPlaytimeRecord:export')")
    @Log(title = "玩耍记录表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LakkUserplaytimerecord lakkUserplaytimerecord) {
        List<LakkUserplaytimerecord> list = lakkUserplaytimerecordService.selectLakkUserplaytimerecordList(lakkUserplaytimerecord);
        ExcelUtil<LakkUserplaytimerecord> util = new ExcelUtil<LakkUserplaytimerecord>(LakkUserplaytimerecord.class);
        util.exportExcel(response, list, "玩耍记录表数据");
    }

    /**
     * 获取玩耍记录表详细信息
     */
//    @PreAuthorize("@ss.hasPermi('lakk:UserPlaytimeRecord:query')")
    @GetMapping(value = "/{userid}")
    public AjaxResult getInfo(@PathVariable("userid") Long userid) {
        return success(lakkUserplaytimerecordService.selectLakkUserplaytimerecordByUserid(userid));
    }

    /**
     * 新增玩耍记录表
     */
//    @PreAuthorize("@ss.hasPermi('lakk:UserPlaytimeRecord:add')")
    @Log(title = "玩耍记录表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LakkUserplaytimerecord lakkUserplaytimerecord) {
        lakkUserplaytimerecord.setUserid(getappid(SecurityUtils.getLoginUser()));
        lakkUserplaytimerecord.setDate(new Date());
        return toAjax(lakkUserplaytimerecordService.insertLakkUserplaytimerecord(lakkUserplaytimerecord));
    }


    /**
     * 修改玩耍记录表
     */
//    @PreAuthorize("@ss.hasPermi('lakk:UserPlaytimeRecord:edit')")
    @Log(title = "玩耍记录表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LakkUserplaytimerecord lakkUserplaytimerecord) {
        return toAjax(lakkUserplaytimerecordService.updateLakkUserplaytimerecord(lakkUserplaytimerecord));
    }


    /**
     * 删除玩耍记录表
     */
//    @PreAuthorize("@ss.hasPermi('lakk:UserPlaytimeRecord:remove')")
    @Log(title = "玩耍记录表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userids}")
    public AjaxResult remove(@PathVariable Long[] userids) {
        return toAjax(lakkUserplaytimerecordService.deleteLakkUserplaytimerecordByUserids(userids));
    }
}
